Method for automatic video face replacement by using a 2D face image to estimate a 3D vector angle of the face image

ABSTRACT

A method for automatic video face replacement includes steps of capturing a face image, detecting a rotation angle of the face image, defining a region to be replaced in the face image, and pasting a region to be replaced of one of the replaced images having the corresponding rotation angle of the face image into a target replacing region. Therefore, the region to be replaced of a static or dynamic face image can be replaced by a replaced image quickly by a single camera without requiring a manual setting of the feature points of a target image. These methods support face replacement at different angles and compensate the color difference to provide a natural look of the replaced image.

REFERENCE TO RELATED APPLICATION

This is a divisional application for applicant's former patentapplication Ser. No. 14/615,770 filed on Feb. 6, 2015, currentlypending.

BACKGROUND OF THE INVENTION

1. Fields of the Invention

The divisional application relates to a method for automatic video facereplacement by using a 2D face image to estimate a 3D vector angle ofthe face image, and more particularly, to the method with the effect ofreplacing a face image by detecting a rotation angle of the face imageand then replacing a region to be replaced of the face image by areplaced image.

2. Descriptions of Related Art

Face replacement technology gains more attentions in recent years,primarily due to its wide scope of applicability in the fields ofmovies, entertainments and medical cosmetology. For example, when amovie is shot, a stuntman's face image is replaced by a main actor'sface image, so that the main actor no longer needs to perform an actionof high level of difficulty, and a cameraman needs not to avoid theangle of shooting at the stuntman's face. Such face replacementtechnique can ensure the safety of the main actor and improve theefficiency of shooting the film and saving the production costeffectively. In the aspect of entertainment, users may replace faceswith others to achieve the effect of having fun. In the aspect ofmedical cosmetology, patients requiring a plastic surgery may observedthe result of the surgery ahead of time before deciding whether or notto take the surgery in order to avoid unexpected results.

In a conventional face replacement technique, the feature points of animage to be replaced and a target image are calculated manually, so asto designate a region and an angle to be replaced, and then the range ofthe calculated feature points of the target image is replaced by a rangeof calculated feature points of the replaced image. However, thistechnique is applicable for the replacement of a single static imageonly, but is difficult to be applied for replacing dynamic images. Inaddition, it is necessary to manually mark the feature points of theimage to be replaced and the target image, and thus the operation isinconvenient to users and time-consuming. Color difference may occur atthe boundary of the replaced image easily, and thus the overall visualperception of the replaced image is unnatural. Furthermore, the methodof estimating a face angle applied in the replacement process is toocomplicated and takes lots of computation time. Therefore, thistechnique fails to provide a quick image replacement.

In view of the aforementioned problems, the inventor of the presentinvention based on years of experience in the related industry toconduct extensive researches and experiments, and finally designed aface replacement technique in accordance with the present invention toovercome the aforementioned problems of the prior art.

SUMMARY OF THE INVENTION

The present invention overcomes the drawbacks of the conventional facereplacement technique that requires the users to manually mark thefeature points of the image to be replaced and the target image andcauses tremendous inconvenience to the users, and the method ofestimating a face angle is time-consuming, and color difference mayoccur at the boundary of the replaced image easily and result in anunnatural visual perception of the replaced image.

To achieve the aforementioned objective, the present invention providesa method for automatic video face replacement by using a 2D face imageto estimate a 3D vector angle of the face image, comprising the stepsof:

using a method for estimating a 3D vector angle from a 2D face image,comprising the steps of:

creating a feature vector template including a feature vector model of aplurality of different rotation angles;

detecting a corner of eye and a corner of mouth in a face image to beprocessed, and defining the corners of eye and the corners of mouth asvertices of a quadrilateral respectively;

defining a sharp point in a vertical direction of the quadrilateralplane, and converting the vertices into 3D coordinates, wherein thesharp point and the vertices of the quadrilateral form a quadrangularpyramid; computing the four vectors from the sharp point to the fourvertices whose coordinates are 3D coordinates to obtain a vector set,and

matching the vector set with the feature vector model to obtain an anglewhich has the shortest distance between a feature vector model and thevector set, and defining the angle value as a rotation angle of theinput face image, and using a method for creating a face replacementdatabase, comprising the steps of:

creating a face database for storing a plurality of replaced images witha face image rotation angle by using the method for estimating a 3Dvector angle from a 2D face image;

defining a region to be replaced in the replaced image; and

using a method for replacing a face image, comprising the steps of:

capturing a face image, and detecting a rotation angle of the face imageaccording to the method for estimating a 3D vector angle from a 2D faceimage;

defining a region to be replaced in the face image, and

pasting a region to be replaced of one of the replaced images with thecorresponding rotation angle of the face image onto a target replacingregion.

Preferably, the region to be replaced is a surface region formed by thevertices.

Preferably, the method for automatic video face replacement furthercomprises the steps of:

obtaining a center point between two adjacent vertices, and shifting thecenter point towards the exterior of the quadrilateral, and

using an arc to connect the vertices and the center point to form theregion to be replaced.

Preferably, the arc is a parabola, and the surface region is in theshape of a convex hull.

Preferably, the corner of eye and the corner of mouth are detected fromtwo eye regions and a mouth region of the face image respectively, and afirst leftmost point and a first rightmost point are obtained from a topedge of the eye region respectively, and a second leftmost point and asecond rightmost point mouth region are obtained from a bottom edge ofthe eye region respectively, and a center point is obtained from twoadjacent points between the first leftmost point, the first rightmostpoint, the second leftmost point and the second rightmost point, andshifting the center point towards the exterior of the quadrilateral, anarc is used for connecting the first leftmost point, the first rightmostpoint, the second leftmost point, the second rightmost point and thecenter point to form a closed surface region which is defined as theregion to be replaced.

Preferably, The method for automatic video face replacement as claimedin claim 1, further comprising the steps of:

calculating the histograms of a R channel, a G channel and a B channelof the replaced image and the region to be replaced (called targetreplacing region) respectively, and normalizing the histogram into aprobability; and

using the probability to compute expectation values of the replacedimage and the target replacing region respectively to obtain a zoomfactor of the replaced image and the target replacing region, andadjusting the values of the R channel, the G channel and the B channelaccording to the zoom factor.

Preferably, the region to be replaced is layered gradually and pastedonto the region to be replaced by an edge feathering method.

Preferably, the method for automatic video face replacement furthercomprises the steps of using the boundary of the region to be replacedof the replaced image and the region to be replaced as standards to seta higher value to the transparency of a pixel at an edge of the regionto be replaced and outside the edge of the region to be replaced, and adecreasingly lower value at a position progressively moving towards theinside of an edge of the region to be replaced.

Preferably, the higher value is equal to 1, and the lower value is equalto 0.

Preferably, the face image is a static image or a dynamic image, and theface image is captured instantly by a camera.

In summation of the description above, the present invention has thefollowing advantages and effects:

-   -   1. The present invention performs the steps of forming the        vertices of a quadrilateral through the corners of eye and        corners of mouth of a planar image, defining a sharp point in        the vertical direction of the quadrilateral, computing the four        vectors from the sharp point to four vertices whose coordinates        are 3D coordinates to obtain the vector set, matching the vector        set with the feature vector model to obtain an angle which has        the shortest distance between a feature vector model and the        vector set, and defining the angle value as the rotation angle        of the input face image. Obviously, the present invention can        estimate the rotation angle of a face image instantly without        any manual operation or complicated and huge computations. The        invention is applicable for dynamic and static images and almost        synchronized with the dynamic image without any delay.    -   2. The present invention defines and forms the region to be        replaced by the corners of eye and the corners of mouth in a        face image, so that the region to be replaced will change        according to the rotation of the face image, so that the face        replacement is done precisely without any deviation. In        addition, the values of the R channel, G channel and B channel        of the target replacing image are adjusted according to the zoom        factors between the RBG color of the replaced image and that of        the target replacing region, and the replaced image is pasted        onto the target replacing region by an edge feathering method,        so that the color of the target replacing region is made to be        natural.    -   3. The present invention simply requires a low cost camera and        personal computer, and does not require the installation of any        additional expensive equipment.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a flow chart of a method for estimating a 3D vector angle froma 2D face images in accordance with the present invention;

FIG. 2 is a schematic view of a first region of interest and a secondregion of interest defined in a face image in accordance with thepresent invention;

FIG. 3 is a schematic view of a vector set obtained from a face image inaccordance with the present invention;

FIG. 4 is a schematic view of a vector set of different rotation anglesof a face image in accordance with the present invention;

FIG. 5 is a flow chart of a method for creating a face replacementdatabase by using a 2D face image to estimate a 3D vector angle of theface image in accordance with the present invention;

FIG. 6 is a schematic view of a region to be replaced defined in areplaced image in accordance with the present invention;

FIG. 7 is a flow chart of a method for automatic video face replacementby using a 2D face image to estimate a 3D vector angle of the face imagein accordance with the present invention;

FIG. 8 is a schematic view of a region to be replaced defined in a faceimage in accordance with the present invention;

FIG. 9 is a schematic view of a region to be replaced pasted onto atarget replacing region in accordance with the present invention, and

FIG. 10 is a schematic view of an application of pasting a replacedimage onto a target replacing region of a face image in accordance withthe present invention.

DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT

The present invention will become more obvious from the followingdescription when taken in connection with the accompanying drawingswhich show, for purposes of illustration only, a preferred embodiment inaccordance with the present invention.

With reference to FIG. 1 for a method for estimating a 3D vector anglefrom a 2D face image in accordance with the present invention, themethod comprises the following steps of:

S001: Create a feature vector template, wherein the feature vectortemplate includes a feature vector model of a plurality of differentrotation angles and a standard eyes distance which is the distancebetween two eyes of the face image and used for scale normalization. Ingeneral, the feature vector model is created offline in advance. For ageneral user's face rotation, the rotation is performed within a rangeof rotation angles (say from −30° to 30°) with respect to the X-axis,Y-axis and Z-axis, so that if the X-axis, Y-axis and Z-axis arequantized into rotation units of N₁, N₂ and N₃ respectively, then afeature vector model containing N feature vectors is formed, and itsmathematical equation 1 is given below:N=N ₁ ×N ₂ ×N ₃  [Mathematical Equation 1]

Therefore, the vector rotation matrixes within a range of the rotationangles with respect to the X-axis, Y-axis and Z-axis are multiplied todefine a feature vector model.

S002: Capture a static or dynamic image by a camera such as a webcam orcapture a single face image 1 through a transmission network as shown inFIG. 2. In this preferred embodiment, Haar features is used as thefeatures for classification, and Cascade Adaboost classifier is used todetect a human face and facial features. To detect a corner of eye and acorner of mouth of the face image 1 effectively, a first region ofinterest 11 (ROI) is defined separately on both left and right halves ofan upper part of the face image 1 as two eye regions 12 in advance, anda second region of interest 13 is defined at a position within one-thirdof a lower part of the face image 1 as a mouth region 14, and a cornerof eye and a corner of mouth are searched from the eye region 12 and themouth region 14 respectively. Since this invention relates to thedetection of corners of eye and corners of mouth, the detection of acorner of eye is used as an example to illustrate the technicalcharacteristics of the invention, wherein the first region of interest11 is defined in the face image first, and after the first region ofinterest 11 is searched, a corner of eye is searched from the eye region12. In a preferred embodiment, the eye region 12 situated on the lefthalf of the face image 1 has a start point from the left side of theface image 1 for scanning the brightness of a skin region. Since theskin brightness of the corner of eye is darker than that of theneighborhood of the corner of eye, therefore the lowest scannedbrightness occurs at the corner of eye, and the eye region 12 situatedon the right half of the face image 1 similarly has a start point fromthe right side of the face image 1 for scanning the brightness of a skinregion to obtain the corner of eye. As to the search for the corner ofmouth, the same method for scanning the corner of eye is used, but thiscorner of eye and corner of mouth searching method is used for thepurpose of illustrating the present invention only, but not intended forlimiting the scope of the invention.

S003: Define the corner of eyes and the corners of mouth are thevertices P₁, P₂, P₃, P₄ of a quadrilateral respectively as shown in FIG.3. Since the size of each face image may not be the same due to thefactor of the shooting distance of each face image 1 from the camera,the distance from the vertices of corners of eye is computed for scalenormalization in order to determine the angle of the face image 1accurately and correct the error by the scale normalization. Since theface image 1 is a 2D image, the coordinates of the vertices are 2Dcoordinates. To standardize the rotation angle of each face image 1 fordifferent face images 1, this preferred embodiment computes the height hand the 2D coordinates (x₀, y₀) and the centroid G of the quadrilateral,while converting the vertices and the centroid into 3D coordinate, sothat the coordinate value of the vertices and the centroid G situated atthe third dimension is equal to 0. For example, the 3D coordinates ofthe centroid are represented by (x₀, y₀, 0), and a multiple constant kis defined, and a sharp point O is extended from the centroid G to apredetermined multiple of height h in a vertical direction of thequadrilateral plane. In other words, the sharp point O is defined at aposition of k times of the height h, such that the 3D coordinates of thesharp point O are represented by (x₀, y₀, kh), and the sharp point O andthe vertices P₁, P₂, P₃, P₄ of the quadrilateral form a quadrangularpyramids, and a scale normalization of the quadrangular pyramid isperformed according to the standard eyes distance and distance betweenthe vertices of the corners of eye, and the four vectors OP₁ , OP₂ , OP₃, OP₄ from the sharp point O to the vertices P₁, P₂, P₃, P₄ are computedto obtain a vector set. In FIG. 4, different rotation angles of the faceimage 1 result in different quadrangular pyramids and different vectorsets.

S004: Compare the vector set with the feature vector model to obtain anangle which has the shortest distance between the feature vector modeland the vector set. Define the angle value as the rotation angle of theinput face image 1.

In FIG. 5, the present invention provides a method for creating a facereplacement database by using a 2D face image to estimate a 3D vectorangle of the face image, and the method comprises the following steps:

S005: Create a face database for storing a plurality of replaced imageswith a face image rotation angle by using the method for estimating a 3Dvector angle from a 2D face image, and obtain a replaced image 2 of therotation angle of the face image 1, wherein the replaced image 2 isobtained by capturing a face image 1 by a camera such as a webcam, andthe face image 1 may be a static or dynamic image, or by selecting anduploading a static or dynamic image by users, and the rotation angles ofthe face image 1 detected by the face angle estimation method are savedone by one to form the replaced image 2.

S006: Define a target replacing region 21 in the replaced image 2 toassure the replacement of the replacing portion by the replaced image 2,wherein the region to be replaced is a surface region formed by thevertices P₁, P₂, P₃, P₄. In a preferred embodiment, a center point C isobtained respectively between two adjacent vertices P₁, P₂, P₃, P₄, andthe center point C is shifted towards the exterior of the quadrilateral,and an arc is used for connecting the vertices and the center point toform a target replacing region 21. In order to provide a natural look ofthe replaced image 2, the arc is a parabola, and the surface region ispreferably in the shape of a convex hull. In FIG. 6, a first leftmostpoint P₅ and a first rightmost point P₆ are obtained from a top edge ofthe eye region 12, such that the first leftmost point P₅ and the firstrightmost point P₆ are higher than the vertices P₁, P₂ of the originalcorner of eye, and a second leftmost point P₇ and a second rightmostpoint P₈ are obtained from the bottom edge of the mouth region 14 suchthat the second leftmost point P₇ and the second rightmost point P₈ arelower than the vertices P₃, P₄ of the original corner of mouth, and acenter point C is obtained from two adjacent points between the firstleftmost point P₅, the first rightmost point P₆, the second leftmostpoint P₇ and the second rightmost point P₈, and the center point C isshifted towards the exterior of the quadrilateral, and an arc is usedfor connecting the first leftmost point P₅, the first rightmost pointP₆, the second leftmost point P₇, the second rightmost point P₈ and thecenter point C to form a closed surface region which is defined as thetarget replacing region 21.

With reference to FIG. 7 for a method for automatic video facereplacement by using a 2D face image to estimate a 3D vector angle ofthe face image, and the method comprises the following steps:

S007: Capture a face image 1 through a camera such as webcam, and theface image 1 may be a static or dynamic image, or select and upload astatic or dynamic face image 1 by users, and a rotation angle of theface image 1 is detected according to the method for estimating a 3Dvector angle from a 2D face image.

S008: Define a region to be replaced 15 in the face image 1 as shown inFIG. 8, wherein the region to be replaced 15 is defined by the samemethod of defining the target replacing region 21 in the aforementionedstep S006, and thus the method will not be repeated.

S009: Search the replaced image 2 with the rotation angle of thecorresponding face image 1, so that the target replacing region 21 ofone of replaced images 2 corresponding to the rotation angle of the faceimage 1 is pasted onto the region to be replaced 15.

S010: Since the sewing and processing portion of the face has beenprocessed by adjusting the color and brightness of the source image, andprocessing the boundary between sewing portions of the image, the resultmust be adjusted after the replacement takes place, so as to give a morenatural and coordinative image. However, the color and brightness of theregion to be replaced 15 and the target replacing region 21 have adifference to a certain extent, so that it is necessary to adjust thecolor and brightness of the target replacing region 21 to provide anatural visual effect of the replaced image. Therefore, the statisticsof the histograms of R channel, G channel and B channel in RGB colorspace of the region to be replaced 15 and the target replacing region 21are taken and normalized into a probability (i), while avoiding a blackregion from affecting the computation result. In the computationprocess, 0 is not included in the range, and the probability is used forcomputing the expected values of the region to be replaced 15 and targetreplacing region 21 as shown in the following mathematical equation 2:

$\begin{matrix}{E = {\sum\limits_{i = 1}^{n}\;{{ip}(i)}}} & \left\lbrack {{Mathematical}\mspace{14mu}{Equation}\mspace{14mu} 2} \right\rbrack\end{matrix}$

Therefore, zoom factors of the R channel, G channel and B channelbetween the region to be replaced 15 and the target replacing region 21are computed, and the values of the R channel, G channel and B channelof the target replacing region 21 are computed according to the zoomfactor as given in the following mathematical equation 3:C′ _(i) =C _(i) *w _(i) ,i=1(B),2(G),3(R),  [Mathematical Equation 3]

S011: Although the color of the target replacing region 21 after beingreplaced may match the expected value of the color of the replacedregion, yet there may be a slight difference of the color and brightnessat the boundary. To compensate the color and bright difference, thetransparency value of the pixels at the boundary of the target replacingregion 21 or outside the boundary is set a higher value, and adecreasingly lower value at a position progressively moving towards theinside of an edge of the region to be replaced. The compensation can berepresented as the e following mathematical equation 4.I _(dst(x,y)) =αI _(src(x,y))+(1−α)I _(tgt(x,y))  [Mathematical Equation4]

Wherein, I_(dst(xy)) is an image of the region after compensation;I_(src(xy)) is an image of the target replacing region 21; I_(tgt(xy))is an image of the region to be replaced 15, and α is the weight in therange [0,1], so that the image to be replaced 2 may be gradually layeredand pasted on the region to be replaced 15 by an edge feathering methodas shown in FIG. 10. As a result, a natural face image 1 is shown in theregion to be replaced 15 after being replaced.

While we have shown and described the embodiment in accordance with thepresent invention, it should be clear to those skilled in the art thatfurther embodiments may be made without departing from the scope of thepresent invention.

What is claimed is:
 1. A method for automatic video face replacement,comprising: creating a face database for storing a plurality ofreplacement face images, each replacement face image having a rotationangle determined according to a method for estimating a 3-D vector anglefrom a 2-D face image; defining a target replacing region in eachreplacement face image; capturing a face image; determining a rotationangle of the captured face image according to the method for estimatinga 3-D vector angle from a 2-D face image; defining a target region inthe captured face image; selecting one of the replacement face imageshaving a rotation angle corresponding to that of the captured faceimage; and placing the target replacing region of the selectedreplacement face image over the target region of the captured faceimage, wherein the method for estimating a 3-D vector angle from a 2-Dface image includes: creating a feature vector template including afeature vector model of a plurality of different rotation angles,detecting a corner of each of two eyes and two corners of a mouth in aface image to be processed, defining the corners of the eyes and the twocorners of the mouth as respective vertices of a quadrilateral, defininga sharp point displaced in an orthogonal direction relative to thequadrilateral plane, converting the vertices into 3-D coordinates,wherein the sharp point and the vertices of the quadrilateral form aquadrangular pyramid, computing four 3-D vectors, each 3-D vectorextending from the sharp point to a respective one of the four verticesof the quadrilateral, wherein the coordinates of said 3-D vectors are3-D coordinates, and wherein said 3-D vectors are computed to obtain avector set, matching the vector set with the feature vector model toobtain an angle which has the shortest distance between a feature vectormodel and the vector set, and defining the obtained angle value as arotation angle of the input face image.
 2. The method for automaticvideo face replacement as claimed in claim 1, wherein the targetreplacing region is a surface region formed by the vertices of thequadrilateral.
 3. The method for automatic video face replacement asclaimed in claim 2, further comprising: obtaining a center point betweentwo adjacent vertices of the quadrilateral; shifting the center pointtowards an exterior of the quadrilateral; and connecting the verticesand the center point with an arc, the arc thereby defining a boundary ofthe surface region.
 4. The method for automatic video face replacementas claimed in claim 3, wherein the arc is a parabola, and the surfaceregion is in the shape of a convex hull.
 5. The method for automaticvideo face replacement as claimed in claim 2, wherein: the corners ofthe eyes are detected from first and second eye regions of the faceimage, respectively, and the corners of the mouth are detected from amouth region of the face image, a first leftmost point and a firstrightmost point are obtained from top edges of the first and second eyeregions, respectively, and a second leftmost point and a secondrightmost point are obtained from a bottom edge of the mouth region, acenter point is obtained from two adjacent points between the firstleftmost point, the first rightmost point, the second leftmost point,and the second rightmost point, the center point then being shiftedtowards the exterior of the quadrilateral, and an arc connects the firstleftmost point, the first rightmost point, the second leftmost point,the second rightmost point, and the shifted center point, the arcthereby defining a boundary of the surface region.
 6. The method forautomatic video face replacement as claimed in claim 1, furthercomprising: calculating histograms of a R channel, a G channel, and a Bchannel of the target region and of the target replacing regionrespectively; normalizing the histograms into a probability; computingrespective expectation values of the target region and the targetreplacing region according to the probability, to thereby obtain a zoomfactor; and adjusting values of the R channel, the G channel and the Bchannel for the target replacing region according to the zoom factor. 7.The method for automatic video face replacement as claimed in claim 6,wherein the target replacing region is layered gradually and pasted ontothe target region according to an edge feathering method.
 8. The methodfor automatic video face replacement as claimed in claim 7, furthercomprising: setting a highest transparency value to pixels disposed atan edge of the target replacing region and outside the edge of thetarget replacing region, and setting progressively decreasingtransparency values to pixels at positions progressively disposedtowards the inside of the edge of the target replacing region.
 9. Themethod for automatic video face replacement as claimed in claim 8,wherein the highest transparency value is equal to 1, and a lowesttransparency value is equal to
 0. 10. The method for automatic videoface replacement as claimed in claim 1, wherein the captured face imageis a static image or a dynamic image, and the captured face image iscaptured instantly by a camera.